# -*- coding: cp936 -*-
import sqlite3
import os

if __name__ == "__main__":
    conn = sqlite3.connect(r'C:\Users\luogeMacWin\Zotero\zotero.sqlite')
    c = conn.cursor()
    c.execute('''
        SELECT [itemID]
            ,[path]
        FROM [itemAttachments]
        where path is not null
    ''')
    result_list = c.fetchall()
    conn.commit()
    
    update_lst = []
    for itemID, path in result_list:
        if len(path.split('/'))==3 and path.startswith('attachments:'):
            update_lst.append(('storage:' + path.split('/')[2], itemID))
    if len(update_lst)>0:
        c.executemany('update itemAttachments set path =? and linkMode=0 where itemID=?',update_lst)
        conn.commit()
    conn.close()
